<template>
  <div id="aCoursesList" class="bg-fa of">

  </div>
</template>
<script>
import course from '@/api/teacher'

export default {

  data () {
    return {
      total:0,
      pageNum:1,
      pageSize:8,
      data:{},
      subjectNestedList: [], // 一级分类列表
      subSubjectList: [], // 二级分类列表
      searchObj: {}, // 查询表单对象
      oneIndex:-1,
      twoIndex:-1,
      buyCountSort:"",
      gmtCreateSort:"",
      priceSort:"",
      currentPage:""
    }
  },

  //获取番剧列表、分类
  created () {
    this.initCourse()
    this.initSubject()
  },

  methods: {
    //查询番剧列表
    initCourse(){
      course.getCourseList(this.pageNum, this.pageSize,this.searchObj).then(response => {
        this.data = response.data.data
      })
    },
    //查询所有一级分类
    initSubject(){
      course.getSubjects().then(response => {
        this.subjectNestedList = response.data.data.list
      })
    },

    //点击一级分类，显示对应的二级分类，二级联动查询数据
    searchOne(subjectParentId, index) {
      this.oneIndex = index//绑定样式
      this.twoIndex = -1
      this.searchObj.subjectId = "";
      this.subSubjectList = [];
      this.searchObj.subjectParentId = subjectParentId;
      this.gotoPage(this.pageNum)

      for (let i = 0; i < this.subjectNestedList.length; i++) {
        if (this.subjectNestedList[i].id === subjectParentId) {
          this.subSubjectList = this.subjectNestedList[i].children
        }
      }
    },

    //点击二级分类，查询数据
    searchTwo(subjectId, index) {
      this.twoIndex = index
      this.searchObj.subjectId = subjectId;
      course.getSortCourseInfo(this.pageNum, this.pageSize,subjectId).then(response => {
        this.data = response.data.data
      })
    },
    //收藏量查询
    searchBuyCount() {
      this.buyCountSort = "1";
      this.gmtCreateSort = "";
      this.priceSort = "";
      this.searchObj.buyCountSort = this.buyCountSort;
      this.searchObj.gmtCreateSort = this.gmtCreateSort;
      this.searchObj.priceSort = this.priceSort;
      this.gotoPage(this.pageNum)
    },
    //更新时间查询
    searchGmtCreate() {
      this.buyCountSort = "";
      this.gmtCreateSort = "1";
      this.priceSort = "";
      this.searchObj.buyCountSort = this.buyCountSort;
      this.searchObj.gmtCreateSort = this.gmtCreateSort;
      this.searchObj.priceSort = this.priceSort;
      this.gotoPage(this.pageNum)
    },
    //价格查询
    searchPrice() {
      this.buyCountSort = "";
      this.gmtCreateSort = "";
      this.priceSort = "1";
      this.searchObj.buyCountSort = this.buyCountSort;
      this.searchObj.gmtCreateSort = this.gmtCreateSort;
      this.searchObj.priceSort = this.priceSort;
      this.gotoPage(this.pageNum)
    },
    //分页查询
    gotoPage(page) {
      this.pageNum = page
      course.getCourseList(page, 8, this.searchObj).then(response => {
        this.data = response.data.data
      })
    },
    handleSizeChange(size) {
      this.pageSize = size
      if(this.twoIndex ===-1) {
        course.getCourseList(this.pageNum, this.pageSize, this.searchObj).then(response => {
          this.data = response.data.data
        })
      }else {
        course.getSortCourseInfo(this.pageNum, this.pageSize,this.searchObj.subjectId).then(response => {
          this.data = response.data.data
        })
      }
    },
    handleCurrentChange(num) {
      this.pageNum = num
      if(this.twoIndex ===-1) {
        course.getCourseList(this.pageNum, this.pageSize, this.searchObj).then(response => {
          this.data = response.data.data
        })
      }else {
        course.getSortCourseInfo(this.pageNum, this.pageSize,this.searchObj.subjectId).then(response => {
          this.data = response.data.data
        })
      }
    },
  }
}
</script>
<style scoped>
  .active {
    background: #409eff;
    border-radius:3px;
    color:#fff
  }
  .hide {
    display: none;
  }
  .show {
    display: block;
    float:left;
  }

</style>
